var obj = {
  aaa: "sadsa",
};
var temp; //临时变量 周转get值
Object.defineProperty(obj, "bbb", {
  //getter
  get() {
    console.log("访问bbb属性", temp);
    // return this._keya; //this指向 obj
    return temp;
  },
  set(newVal) {
    console.log("改变bbb属性", newVal);
    // this._keya = newVal;
    temp = newVal;
  },
});
obj.aaa = "lllll2222";
obj.bbb = 5555; //  改变bbb属性 5555
console.log(obj.bbb); //  访问bbb属性 5555        5555
console.log(obj);

function defineReactive(data, key, val) {
  Object.defineProperty(data, key, {
    get() {
      console.log(`访问${key}属性`, val);
      return val;
    },
    set(newVal) {
      console.log(`改变${key}属性`, newVal);
      if (val === newVal) return;
      val = newVal;
    },
  });
}
defineReactive(obj, "ssss", 111);
console.log(obj.ssss); //  访问ssss属性 111          111
console.log(obj);

let lll = {
  name: "wei",
  age: 22,
  gender: "难",
};
Object.keys(lll).forEach(function (key) {
  let temp = this[key];
  Object.defineProperty(lll, key, {
    get: function () {
      console.log("get");
      return temp;
    },
    set: function (val) {
      console.log("监听到数据发生了变化", key, val);
      temp = val;
    },
  });
});
lll.age = 44;
